﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SherlockGUI.CFG;

namespace SherlockGUI.Dlg
{
    public partial class LogCfgDlg : Form
    {
        public LogCfgDlg()
        {
            InitializeComponent();
        }

        private void LogCfgDlg_Load(object sender, EventArgs e)
        {
            label_PicPath.Text = GlobalCfg.m_LogCfg.strPicLogPath;

            numericUpDown_MaxPicNum_NG.Value = GlobalCfg.m_LogCfg.PicLogCfg_NG.iMaxPicNum;
            checkBox_SaveNGPic.Checked = GlobalCfg.m_LogCfg.PicLogCfg_NG.bSavePic;

            numericUpDown_MaxPicNum_OK.Value = GlobalCfg.m_LogCfg.PicLogCfg_OK.iMaxPicNum;
            checkBox_SaveOKPic.Checked = GlobalCfg.m_LogCfg.PicLogCfg_OK.bSavePic;


            checkBox_SaveCheckResult.Checked = GlobalCfg.m_LogCfg.InspectCount.bSaveCount;
        }

        private void button_SelNewPicPath_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog();
            dialog.Description = "请选择需要保存的文件夹";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (string.IsNullOrEmpty(dialog.SelectedPath))
                {
                    MessageBox.Show(this, "文件夹路径不能为空", "提示");
                    return;
                }

                label_PicPath.Text = dialog.SelectedPath;
            }
        }

        private void OK_Click(object sender, EventArgs e)
        {
            GlobalCfg.m_LogCfg.strPicLogPath = label_PicPath.Text.TrimEnd('\\');

            try
            {
                GlobalCfg.m_LogCfg.PicLogCfg_NG.iMaxPicNum = (int)numericUpDown_MaxPicNum_NG.Value;
                GlobalCfg.m_LogCfg.PicLogCfg_NG.bSavePic = checkBox_SaveNGPic.Checked;
                GlobalCfg.m_LogCfg.PicLogCfg_NG.strPicPath = GlobalCfg.m_LogCfg.strPicLogPath + "\\NG\\";
                if (!System.IO.Directory.Exists(GlobalCfg.m_LogCfg.PicLogCfg_NG.strPicPath))
                {
                    System.IO.Directory.CreateDirectory(GlobalCfg.m_LogCfg.PicLogCfg_NG.strPicPath);//不存在就创建目录   
                }
                GlobalCfg.m_LogCfg.PicLogCfg_OK.iMaxPicNum = (int)numericUpDown_MaxPicNum_OK.Value;
                GlobalCfg.m_LogCfg.PicLogCfg_OK.bSavePic = checkBox_SaveOKPic.Checked;
                GlobalCfg.m_LogCfg.PicLogCfg_OK.strPicPath = GlobalCfg.m_LogCfg.strPicLogPath + "\\OK\\";
                if (!System.IO.Directory.Exists(GlobalCfg.m_LogCfg.PicLogCfg_OK.strPicPath))
                {
                    System.IO.Directory.CreateDirectory(GlobalCfg.m_LogCfg.PicLogCfg_OK.strPicPath);//不存在就创建目录   
                }

                GlobalCfg.m_LogCfg.InspectCount.bSaveCount = checkBox_SaveCheckResult.Checked;

                GlobalCfg.SaveLogCfg();
                Close();
            }
            catch (Exception)
            {

            }
        }
    }
}
